<?php
$folderConfig = $model->params;
$folderConfig['base_path'] = substr($folderConfig['elfinder']['base_path'], 3) . $model->folder_id . '/';
$folderConfig['base_url'] = $folderConfig['elfinder']['base_url'] . $model->folder_id . '/';

$baseUrl = Yii::app()->baseUrl;
$cs = Yii::app()->getClientScript();
$cs->registerScriptFile($baseUrl . '/js/jquery.number.min.js', CClientScript::POS_BEGIN);
?>

<div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
    <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
        <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active">
            <a href="#tabs-1">General</a>
        </li>
        <li class="ui-state-default ui-corner-top">
            <a href="#tabs-2">Information</a>
        </li>
        <li class="ui-state-default ui-corner-top">
            <a href="#tabs-3">Images</a>
        </li>
    </ul>
    
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id'    => 'input-form',
        'focus' => array($model, 'title'),
        'errorMessageCssClass' => 'error',
        'htmlOptions'          => array(
            'enctype' => 'multipart/form-data',
            'class'   => 'form',
        ),
    ));

    echo $form->hiddenField($model, 'folder_id');
    echo $form->hiddenField($model, 'images');
    ?>
    <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
        <ul>
            <li>
                <?php echo $form->labelEx($model, 'type_id', array('class' => 'desc')); ?>

                <div>
                <?php
                $data = DNewsletterType::model()->getMenu(true);
                $attribute = 'type_id';

                $this->widget('ArrayToDropDownList', array(
                    'model'         => $model,
                    'attribute'     => $attribute,
                    'data'          => $data,
                    'parentId'      => 3, //product
                    'disableParent' => true,
                    'selected'      => $model->getAttribute('type_id'),
                    'htmlOptions'   => array(
                        'class'    => 'select',
                    ),
                ));
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'status';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                $attribute = 'activated_flag';
                echo $form->checkbox($model, $attribute, array(
                    'style' => 'display:inline-block;',
                ));
                echo CHtml::label($model->getAttributeLabel($attribute), 'DProductShop_activated_flag', array(
                    'style' => 'display:inline-block;',
                    'class' => 'desc',
                ));

                $attribute = 'hot';
                echo $form->checkbox($model, $attribute, array(
                    'style' => 'display:inline-block; margin-left: 25px;',
                ));
                echo CHtml::label($model->getAttributeLabel($attribute), 'DProductShop_hot', array(
                    'style' => 'display:inline-block;',
                    'class' => 'desc',
                ));
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'title';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                echo $form->textField($model, $attribute, array(
                    'class' => 'text large',
                ));
                echo $form->error($model, $attribute);
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'code';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                echo $form->textField($model, $attribute, array(
                    'class' => 'text large',
                ));
                echo $form->error($model, $attribute);
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'price';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                echo '<strong style="float: left; margin: 5px 5px 0 0; font-size:1.2em;">$</strong>';
                echo $form->textField($model, $attribute, array(
                    'class' => 'text small',
                ));
                echo $form->error($model, $attribute);
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'promotional_price';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                echo '<strong style="float: left; margin: 5px 5px 0 0; font-size:1.2em;">$</strong>';
                echo $form->textField($model, $attribute, array(
                    'class' => 'text small',
                ));
                echo $form->error($model, $attribute);
                ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'counter';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                echo $form->textField($model, $attribute, array(
                    'class' => 'text small',
                ));
                echo $form->error($model, $attribute);
                ?>
                </div>
            </li>
            
            <li>
                <?php
                $attribute = 'file_download';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                <?php
                $src = $model->getAttribute('file_download');
                $this->widget('ext.mylib.widgets.FilePicker.FilePickerWidget', array(
                    'config'    => $folderConfig,
                    'model'     => $model,
                    'attribute' => $attribute,
                ));
                ?>
                </div>
            </li>
        </ul>
    </div>
    
    <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
        <ul>
            <li>
                <?php
                $attribute = 'short_content';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                    <?php
                    $this->widget('ext.ckeditor.CKEditorWidget', array(
                        'model'     => $model,
                        'attribute' => $attribute,
                        'config'    => array(
                            'height'   => 100,
                        ),
                        'paramsElFinder' => $model->params,
                    ));
                    echo $form->error($model, $attribute);
                    ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'detailed_content';
                echo $form->labelEx($model, 'detailed_content', array('class' => 'desc'));
                ?>

                <div>
                    <?php
                    $this->widget('ext.ckeditor.CKEditorWidget', array(
                        'model'     => $model,
                        'attribute' => $attribute,
                        'config'    => array('toolbar' => 'DFull',),
                        'folderID' => $model->folder_id,
                    ));

                    echo $form->error($model, $attribute);
                    ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'keyword';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>

                <div>
                    <?php
                    echo $form->textField($model, $attribute, array('class' => 'text large'));
                    echo $form->error($model, $attribute);
                    ?>
                </div>
            </li>

            <li>
                <?php
                $attribute = 'description';
                echo $form->labelEx($model, $attribute, array('class' => 'desc'));
                ?>
                <div>
                    <?php
                    echo $form->textField($model, $attribute, array('class' => 'text large'));
                    echo $form->error($model, $attribute);
                    ?>
                </div>
            </li>
        </ul>
    </div>
    <div id="tabs-3" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">
        <?php
        $attribute = 'images';
        $images = explode(';', $model->getAttribute($attribute));
        
        for ($i=0; $i<6; $i++) {
            if ( isset($images[$i]) && (! empty($images[$i])) ) {
                $src = $folderConfig['base_url'] . $images[$i];
            } else {
                $src = null;
            }
            $this->widget('ext.mylib.widgets.FilePicker.ImagePickerWidget', array(
                'config' => $folderConfig,
                'name'   => "Image " . ($i + 1),
                'id'     => "imagePicker_" . ($i + 1),
                'src' => $src,
            ));
        }
        ?>
        <div class="clear"></div>
    </div>
</div>

<div style="text-align: center;">
    <?php
    echo CHtml::submitButton($model->isNewRecord ? 'CREATE' : 'SAVE', array(
        'id'    => 'btn-save',
        'class' => 'ui-state-default ui-corner-all ui-button'
    ));
    echo CHtml::button('RESET', array(
        'id'    => 'btn-reset',
        'class' => 'ui-state-default ui-corner-all ui-button',
        'style' => 'margin:0 10px;',
    ));
    echo CHtml::button('CANCEL', array(
        'class' => 'ui-state-default ui-corner-all ui-button btn-cancel'
    ));
    ?>
</div>

<?php $this->endWidget(); //end form ?>

<script type="text/javascript">
$('#DProductShop_price').number( true, 2 );
$('#DProductShop_promotional_price').number( true, 2 );
</script>